﻿using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.Serialization;
using System.Collections;
using System.Data;
using System.ComponentModel;
using System.Data.OracleClient;
namespace INTEX.DataBase.Tools
{
    public partial class INTEXDBC
    {
        public void MapLOGINFO(ref DataRow dwLocal, DataRow dwData)
        {
            BlindMap(ref dwLocal, dwData);
        }
        public void SaveLOGINFO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            DataRow dwLocal = null;
            bool flgExist = false;
            Result = QueryLOGINFO(dwData);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                if (tbLocal.Rows.Count > 0)
                {
                    flgExist = true;
                    dwLocal = tbLocal.Rows[0];
                }
                else
                {
                    dwLocal = tbLocal.NewRow();
                }
            }
            if (dwLocal == null)
                dwLocal = dwData;
            MapLOGINFO(ref dwLocal, dwData);

            if (!flgExist)
            {
                InsertLOGINFO(dwLocal);
            }
            UpdateLOGINFO(dwLocal);

        }
        public void InsertLOGINFO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            or1 = OracleDB.CreateCommand();
            DataSet result = new DataSet();
            or1.CommandText = "INSERT INTO LOGINFO (FINTERID, FDESIGNNAME,FEDITDATE,FCLOTHNO,FCOLORNO,CAD2ITXSTATUS,FCADKEY) "
                + " VALUES (:FINTERID, :FDESIGNNAME,:FEDITDATE,:FCLOTHNO, :FCOLORNO,:CAD2ITXSTATUS,:FCADKEY) ";

            or1.Parameters.Add("FINTERID", OracleType.NVarChar).Value = dwData["FINTERID"].ToString();
            or1.Parameters.Add("FDESIGNNAME", OracleType.NVarChar).Value = dwData["FDESIGNNAME"].ToString();
            or1.Parameters.Add("FEDITDATE", OracleType.NVarChar).Value = dwData["FEDITDATE"].ToString();
            or1.Parameters.Add("FCLOTHNO", OracleType.NVarChar).Value = dwData["FCLOTHNO"].ToString();
            or1.Parameters.Add("FCOLORNO", OracleType.NVarChar).Value = dwData["FCOLORNO"].ToString();
            or1.Parameters.Add("CAD2ITXSTATUS", OracleType.NVarChar).Value = dwData["CAD2ITXSTATUS"].ToString();
            or1.Parameters.Add("FCADKEY", OracleType.NVarChar).Value = dwData["FCADKEY"].ToString();
            Connect2Proxy(or1);
        }
        public DataSet QueryLOGINFO(DataRow dwData, int option = 1)
        {
            DataSet setReturn = new DataSet();
            DataSet Result = new DataSet();
            DataTable tbLocal = null;
            OracleCommand or1 = OracleDB.CreateCommand();
            // APZMANDANT  APZART APZVAR APZANRKRS APZALFDNR APZSTUFE
            switch (option)
            {
                case 1:
                    or1.CommandText = "SELECT * FROM LOGINFO WHERE FINTERID=:FINTERID";
                    or1.Parameters.Add("FINTERID", OracleType.NVarChar).Value = dwData["FINTERID"].ToString();
                    break;
                case 2:
                    or1.CommandText = "SELECT * FROM LOGINFO   WHERE SUBSTR('00000000000'||FINTERID,-10)=(SELECT MAX(SUBSTR('00000000000'||FINTERID,-10)) FROM LOGINFO)";
                    break;
                case 3:
                    break;
                case 4:
                    break;
                case 5:
                    break;
                default:

                    break;
            }

            Result = Connect2Proxy(or1);
            if (Result.Tables.Count > 0)
            {
                tbLocal = Result.Tables[0];
                tbLocal.TableName = "LogInfo";
            }
            setReturn.Merge(Result);
            return setReturn;
        }
        public void UpdateLOGINFO(DataRow dwData, string ITXDBVERSION = "50.24")
        {
            OracleCommand or1;
            DataSet Result = new DataSet();
            or1 = OracleDB.CreateCommand();

            #region====Command====
            or1.CommandText = "UPDATE LOGINFO SET "
                + "FDESIGNNAME=:FDESIGNNAME,"
                + "FEDITDATE=:FEDITDATE,"
                + "FCLOTHNO=:FCLOTHNO,"
                + "FCOLORNO=:FCOLORNO,"
                + "CAD2ITXSTATUS=:CAD2ITXSTATUS,"
                + "FCADKEY=:FCADKEY "
                + " WHERE  "
                + "  FINTERID=:FINTERID";
            #endregion

            #region====Parameters====
            or1.Parameters.Add("FINTERID", OracleType.NVarChar).Value = dwData["FINTERID"].ToString();
            or1.Parameters.Add("FDESIGNNAME", OracleType.NVarChar).Value = dwData["FDESIGNNAME"].ToString();
            or1.Parameters.Add("FEDITDATE", OracleType.NVarChar).Value = dwData["FEDITDATE"].ToString();
            or1.Parameters.Add("FCLOTHNO", OracleType.NVarChar).Value = dwData["FCLOTHNO"].ToString();
            or1.Parameters.Add("FCOLORNO", OracleType.NVarChar).Value = dwData["FCOLORNO"].ToString();
            or1.Parameters.Add("CAD2ITXSTATUS", OracleType.NVarChar).Value = dwData["CAD2ITXSTATUS"].ToString();
            or1.Parameters.Add("FCADKEY", OracleType.NVarChar).Value = dwData["FCADKEY"].ToString();
            #endregion

            Connect2Proxy(or1);
        }
    }
}
